var over = 0;
var action = 0;

var thisPage = {
    first: 0,
    // 初始化页面
    OnPageLoad: function () {
        // 取得款号（各个子款号）
        //arrStyleNo = parent.$("#SuitStyleNo").val().split("/");
        $("#grid__wrapper").hide();
      
        $("#wizard").scrollable({
            onBeforeSeek: function (event, i) {
                if (parseInt(i) === 1) {
                  //  var n = $("input[type='checkbox'][name='_check_row_colour']:checked").length;
                    if ($("#Begin").val() === "" || $("#PeriodDays").val()==="") {
                        ShowErrorMessagePanel('条件不能为空值。');
                        $(".error-msg").css({top: '10px'});
                        return false;
                    }
                }
              
              
            }
        });

        setTimeout(function () {
            $('#loading').hide();
        }, 300);
    }
};





//-----------------------------------------------------------------------------
// 数据保存部分
//-----------------------------------------------------------------------------
var savePage = {
    $currRow: null,
    CreateInputTable: function () {
       
        // step3: 设置表格内容
        content = '';
        $("#tabData tbody").empty();
        var n=$("#AccoutingPeriodNum").val();
        var _periodDays=parseInt($("#PeriodDays").val());
        var startDate=$("#Begin").val();
        var endDate="";
        for(var i=0;i<n;i++) {          
                endDate=new Date(new Date(startDate).getTime()+(_periodDays - 1)*24*60*60*1000);
                var endDate1=endDate.getFullYear()+'-'+(parseInt(endDate.getMonth())+1)+'-'+endDate.getDate();
                content += '<tr>';
                content +="<td>"+(i+1)+"</td><td>"+startDate +"</td><td>" + endDate1 +"</td>";
                content += '</tr>';
                $("#tabData tbody").append(content);
                content = '';
                var startDate1=new Date(new Date(endDate).getTime()+1*24*60*60*1000);
                startDate=startDate1.getFullYear()+'-'+(parseInt(startDate1.getMonth())+1)+'-'+startDate1.getDate();
            };
       
        setOneTableRowColor("tabData");
    //    SetSlaveTableHeight();

        $("#grid__wrapper").show();
    },
   
    // 得到要保存的数据
    GetLinesData: function () {      
        var itemList = [];
        // 得到修改过数据
        $('#tabData tbody').find("tr").each(function () {
            var rowEntity = {};
            var _startDate = $.trim($(this).find('td').eq(1).text());  
            var _endDate = $.trim($(this).find('td').eq(2).text());                           // 样品数            
            // 设置每行的数据
            rowEntity['apYear'] = parseInt($("#ApYear").val());           
            rowEntity['startDate'] = _startDate;
            rowEntity['endDate'] = _endDate;
            rowEntity['createdBy'] = parent.$("#UserId").val();
            rowEntity['updatedBy'] = parent.$("#UserId").val();

            itemList.push(rowEntity);
        });

        return JSON.stringify(itemList);
    },
    DoSave: function () {       
        //step 2、执行处理
        $.ajax({
            type: "POST",
            url: parent.basePath + "/financial/accouting_period/insert.html",
            timeout: 30 * 1000,
            data: savePage.GetLinesData(),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            beforeSend: function () {
            }
        }).done(function (data) {
            if ($.isEmptyObject(data) === false) {                              
                parent.ShowSuccessMessagePanel("增加成功。");
            }
            //刷新
            parent._Instance.PageInit();
            closePopupWnd();
        }).fail(function (data) {
            ajaxError(data, 1);
            $(".error-msg").css({top: '10px'});
        }).always(function ( ) {
        });
    }
};

//-----------------------------------------------------------------------------
// 页面初始化
//-----------------------------------------------------------------------------
function onPageReady() {
     $('#SpinnerApYear span:last-child').on('click', function (event) {
        $('#ApYear').val(parseInt($('#ApYear').val(), 10) + 1);
        event.stopPropagation();
    });
    $('#SpinnerApYear span:first').on('click', function (event) {
        $('#ApYear').val(parseInt($('#ApYear').val(), 10) - 1);
        event.stopPropagation();
    });
      window.laydate.render({
        elem: '#Begin',
        theme: '#393D49',
        trigger: 'click'
    });
    thisPage.OnPageLoad();
}

// 画面大小或者位置移动
function onPageResize() {
    var _h = $(window).height();
    var _w = $(window).width();

    $("#wizard").css({width: _w, height: _h});
    $("div.page").css({width: _w, height: _h});

    over = 1;
}




